
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>员工</title>
    <link rel="stylesheet" type="text/css" href="/static/plugins/easyui/themes/material/easyui.css">
    <link rel="stylesheet" type="text/css" href="/static/plugins/easyui/themes/icon.css">
    <script type="text/javascript" src="/static/plugins/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="/static/plugins/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/static/plugins/easyui/locale/easyui-lang-zh_CN.js"></script>
    <script>
        $(function () {
            //编辑对话框
            $("#product_dig").dialog({
                width: 400,
                height: 330,
                closed: true,
                cache: false,
                modal: true,
                buttons:'#product_dig_btn',
                onClose:function () {
                    //关闭dialog,清空表单数据
                    $("#product_form").form("clear");
                }
            })

            $('#product_dg').datagrid({
                url:'/product/queryForList.do',
                fitColumns:true,
                fit:true,
                nowrap:true,
                pagination:true,
                singleSelect:true,
                toolbar:"#product_tb",
                onLoadSuccess:function (data) {
                    $("#productsortoneid").combobox("loadData",data.sort)
                },
                rownumbers:true,
                columns:[[
                    {
                        field:'productName',title:'商品名称',width:100,formatter: function (value) {
                            return "<span title='" + value + "'>" + value + "</span>";
                        }
                    },
                    {field:'productSn',title:'商品编号',width:100},
                    {field:'costPrice',title:'成本价格',width:100},
                    {field:'salePrice',title:'销售价格',width:100},
                    {field:'one',title:'一级分类',width:100,
                        formatter:function (value, row, index) {
                            return row.one ? row.one.name : ""
                        }},
                    {field:'two',title:'二级分类',width:100,
                        formatter:function (value, row, index) {
                            return row.two ? row.two.name : ""
                        }},
                    {
                        field:'remark',title:'商品备注',width:150,formatter: function (value) {
                            return "<span title='" + value + "'>" + value + "</span>";
                        }
                    }
                ]]
            });

            $("#keyword_text").textbox({
                prompt:"请输入商品编号或商品名称",
                width:170
            });

            $("input[name='two.id']").combobox({
                panelHeight:'auto',
                onChange:function (index, row) {
                    url:'/productSortTwo/selectByParentSn.do'
                }
            });
            //二级联动
            $("#productsortoneid").combobox({"onChange":function (data) {
                    console.log(this);

                    $.get("/productSortTwo/queryBySn.do",{sn:data},function (two) {
                        $("#productSortTwoId").combobox("loadData",two)
                    })
                }})
        })
        /*提交表单*/
        function submitForm() {
            $('#product_form').form({
                url:'/product/saveOrUpdate.do',
                success:function(data){
                    var data =  $.parseJSON(data);
                    if (data.success) {
                        $.messager.alert('温馨提示','保存成功','info',function () {

                            closeWin();
                            $('#product_dg').datagrid("reload");
                        });
                    }
                    else{
                        $.messager.alert('温馨提示',data.msg);
                        closeWin();
                    }
                }
            });

            $('#product_form').submit();
        }

        function saveProduct() {

            $("#product_dig").dialog("setTitle","新增商品");
            $("#product_dig").dialog("open");
        }
        /*编辑*/
        function editProduct() {
            var tr = $('#product_dg').datagrid("getSelected");
            if (!tr) {
                //没有选中
                $.messager.alert('温馨提示',"至少选中一条数据");
                return;
            }

            $("#product_dig").dialog("setTitle","编辑商品");
            $("#product_dig").dialog("open");
            //数据回显
            tr["one.id"] = tr.one.id;
            tr["two.id"] = tr.two.id;
            $('#product_form').form("load",tr);
        };
        /*删除*/
        function deleteProduct() {
            var tr = $('#product_dg').datagrid("getSelected");
            if (!tr) {
                //没有选中
                $.messager.alert('温馨提示',"至少选中一条数据");
                return;
            }
            $.get("/product/delete.do",{id:tr.id},function (data) {
                if (data.success) {
                    $.messager.alert('温馨提示','删除成功','info',function () {


                        $('#product_dg').datagrid("reload");
                    });
                }
                else{
                    $.messager.alert('温馨提示',data.msg);


                }
            })
        }

        /*离职*/
        function changeProduct() {
            var tr = $('#product_dg').datagrid("getSelected");
            if (!tr) {
                //没有选中
                $.messager.alert('温馨提示',"至少选中一条数据");
                return;
            }
            $.get("/product/changeState.do",{id:tr.id},function (data) {
                if (data.success) {
                    $.messager.alert('温馨提示','操作成功','info',function () {


                        $('#product_dg').datagrid("reload");
                    });
                }
                else{
                    $.messager.alert('温馨提示',data.msg);


                }
            })
        }
        /*高级查询*/
        function queryData() {
            var keyword=  $("input[name='keyword']").val();
            var one =$("#productsortoneid").val()
            var two =$("#productSortTwoId").val()
            $("#product_dg").datagrid("load",{"keyword":keyword,"one":one,"two":two});
        }

        /*刷新*/
        function reloadwin() {
            $('#product_dg').datagrid("reload");
        }

        /*关闭对话框*/
        function closeWin() {
            $("#product_dig").dialog("close")
            $('#product_form').form("clear")
        }


    </script>
</head>
<body>

<table id="product_dg"></table>
<div id="product_tb" >
    <a class="easyui-linkbutton" onclick="saveProduct()" data-options="iconCls:'icon-add',text:'新增'"></a>
    <a class="easyui-linkbutton" onclick="editProduct()" data-options="iconCls:'icon-edit',text:'编辑'"></a>
    <shiro:hasPermission name="product:deleteByPrimaryKey">
    <a class="easyui-linkbutton" onclick="deleteProduct()" data-options="iconCls:'icon-remove',text:'删除'"></a>
    </shiro:hasPermission>
    <a id="btn_change" class="easyui-linkbutton" onclick="changeProduct()" data-options="iconCls:'icon-no',text:'禁用'"></a>
    <a class="easyui-linkbutton" onclick="reloadwin()" data-options="iconCls:'icon-reload',text:'刷新'"></a>
    <input id="keyword_text" class="easyui-textbox" style="width: 85px" type="text" name="keyword"/>
    <input class="easyui-combobox" name="sortOne" id="productsortoneid"
           data-options="valueField:'sn',textField:'name',panelHeight:'auto'," prompt="选择一级分类">

    <input type="text" class="easyui-combobox" name="sortTwo" id="productSortTwoId"
           data-options="valueField:'id',textField:'name',panelHeight:'auto'," prompt="选择二级分类">
    <a class="easyui-linkbutton" onclick="queryData()" data-options="iconCls:'icon-search',text:'查询'"></a>

</div>
<div id="product_dig">
    <form id="product_form" >
        <table align="center" >
            <input type="hidden" name="id">
            <br>
            <br>

            <tr>
                <td>一级分类:</td>
                <td>
                    <input class="easyui-combobox" type="text" name="one.id"
                           data-options="valueField:'id',textField:'name',
                                         url:'/productSort/query.do',panelHeight:'auto'"/>
                </td>
            </tr>

            <tr>
                <td>二级分类:</td>
                <td>
                    <input id="sortTwo" class="easyui-combobox" type="text" name="two.id"
                           data-options="valueField:'id',textField:'name',
                                         url:'/productSortTwo/query.do',panelHeight:'auto'"/>
                </td>
            </tr>

            <tr>
                <td>商品名称:</td>
                <td>
                    <input class="easyui-textbox" type="text" name="productName"  />
                </td>
            </tr>

            <tr>
                <td>商品编号:</td>
                <td>
                    <input class="easyui-textbox" type="text" name="productSn" prompt="编号由系统自动生成" readonly/>
                </td>
            </tr>

            <tr>
                <td>积分:</td>
                <td>
                    <input class="easyui-textbox" type="text" name="integral"  />
                </td>
            </tr>

            <tr>
                <td>零售价格:</td>
                <td>
                    <input class="easyui-textbox" type="text" name="salePrice"  />
                </td>
            </tr>

            <tr>
                <td>成本价格:</td>
                <td>
                    <input class="easyui-textbox" type="text" name="costPrice"  />
                </td>
            </tr>

            <tr>
                <td>商品备注:</td>
                <td>
                    <input class="easyui-textbox" type="text" name="remark"  />
                </td>
            </tr>
        </table>

    </form>
</div>
<!--对话框底部工具栏-->
<div id="product_dig_btn">
    <a class="easyui-linkbutton" onclick="submitForm()" data-options="iconCls:'icon-save',text:'保存'"></a>
    <a class="easyui-linkbutton" onclick="closeWin()" data-options="iconCls:'icon-cancel',text:'取消'"></a>
</div>

</body>
</html>
